package netty.buffer;

import netty.common.Constant;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author cyt
 * @create 2020-11-04 14:44
 */
public class TestC {
    /**
     * 在内存中修改 文件信息
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        String filepath = Constant.FILEPATH;
        RandomAccessFile rw = new RandomAccessFile(filepath + "channel.txt", "rw");
        FileChannel channel = rw.getChannel();
        MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, 5);
        map.put(0, (byte) 'h');
        map.put(3, (byte) '9');
        rw.close();
        System.out.println("修改成功 ！ ");
    }
}
